#!/usr/bin/perl

#
#  $proj_name.pl
#  Copyright (C) Andrew Martin 2011 <andrew@marnick.com>
#   
 # $proj_name is free software: you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the
 # Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # 
 # $proj_name is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 # See the GNU General Public License for more details.
 # 
 # You should have received a copy of the GNU General Public License along
 # with this program.  If not, see <http://www.gnu.org/licenses/>.
 

use File::Basename;

use Gtk2 -init;
my $builder_file = "NewPerlGlade.glade";
my $builder = Gtk2::Builder->new();
$builder->add_from_file( $builder_file ) or die "Couldn't read $builder_file";
$builder->connect_signals( undef );
my $window = $builder->get_object( "window" ) or die "Error while setting up GUI";
$window->show_all();
$project_name = $builder->get_object("project_name"); 

$window->signal_connect (destroy => sub { Gtk2->main_quit });

# set up globals (yuck! ) and initiate some objects.
$create_dia=$builder->get_object("new_dia");
$statusbar = $builder->get_object("statusbar");
$context_id = $statusbar->get_context_id (__PACKAGE__);
$statusbar->push ($context_id, ' ' . "Starting NewGladePerl.");
$filechooserdialog=$builder->get_object("filechooserdialog1");
$apptypecombo=$builder->get_object("App_type");
$about=$builder->get_object("about");

# get application template names from ~/GtkPerl/src and plug them into 
# the combo box for selection by user.
my $filename;
my @files=<~/PerlGtk/src/*.glade>;
foreach $filename (@files){
  my $file=basename($filename);
  my @bits = split(/\./,$file);
  $apptypecombo->append_text($bits[0]);
}
$apptypecombo->set_active(0);

# Dealloc builder
print OUT "\$builder = undef;\n";
Gtk2->main;

#-----------------------------
sub gtk_widget_destroy{ 
#-----------------------------
	print "hello\n";
	exit();
} 

#-----------------------------
sub on_imagemenuitem1_activate{ 
#-----------------------------
	$create_dia->show();

} 

#-----------------------------
sub imagemenuitem2_activate_cb{ 
#-----------------------------
	my $res=$filechooserdialog->run();
	print "Res:" . $res . "\n";

	my $file=$filechooserdialog->get_filename();



	$statusbar->push ($context_id, ' ' . "Project:$file.");
	$filechooserdialog->hide();
} 

#-----------------------------
sub gtk_widget_destroy{ 
#-----------------------------
	print "hello\n";
	exit();
} 

#-----------------------------
sub build{ 
#-----------------------------
	$res=`~/bin/perlgtk $project`;
} 

#-----------------------------
sub about{ 
#-----------------------------

	$res=$about->run();
	if ($res eq "cancel"){	
	  $about->hide();
	}
} 

#-----------------------------
sub new_dia_cancel_clicked_cb{ 
#-----------------------------
	$create_dia->hide();

	# grab user selections from dialog
} 

